<!--
- File:    微信文章推广详细页.
-->
<template>
  <div class="newdetail p20 bg_fff">
    <iframe ref="iframe" width="100%" :src="newsInfo.forward_url" frameborder="0"></iframe>
    <back-nav></back-nav>
  </div>
</template>

<script>
//  import $ from 'jquery'
  let avatar = require('../../assets/images/avatar.png')
//  let bg = require('../../assets/images/erweim.png')
  export default{
    data() {
      return {
        id: this.$route.params.id,
        newsInfo: {}
      }
    },
    components: {},
    created() {
//      this.getNewsDetail(this.id)
      this.init()
    },
    mounted() {
      this.setIframeHeight(this.$refs.iframe)
    },
    methods: {
      setIframeHeight(iframe) {
        if (iframe) {
          iframe.height = document.documentElement.clientHeight
        }
      },
      init() {
        this.$request.getNewsDetail(this.id).then(article => {
          this.$request.getMemberInfo().then(memberInfo => {
            if (!memberInfo.member_avatar || memberInfo.member_avatar == '') {
              memberInfo.member_avatar = avatar
            }
//            var inviter = '<div id="bgimg" style="background: url(' + bg + ') no-repeat; background-size: cover;  width:100%; height:600px;text-align: center"><div style="width:100%;margin: 0 auto;margin-bottom: 54px;overflow: hidden;"><div class="padding:15px; color:#fff;text-align: center; margin-top:20px;"><div style="width:100px; height:100px; border-radius:50%;overflow:hidden; margin:20px auto 5px;"><img style="width:100%;" src="' + memberInfo.member_avatar + '"></div> <div style=" font-size:28px; width:100%;margin-top:10px;display:inline-block; vertical-align:middle;"><p>' + memberInfo.member_name + '</p> <p>为您推荐金品种子商城</p></div></div> <div style="text-align:center; font-size:24px;color:#fff;"><img style="width:240px; height:240px; margin:0 auto; border:8px #fff solid;border-radius:10px;" src="' + memberInfo.qrcode_image + '"> <p style="font-size:18px; color:#000;">长按二维码点击识别二维码</p></div></div></div>'
//            var backNave = ''
//            backNave += '<div style="position: fixed;bottom: 0;width: 100%;">'
//            backNave += '<a href="news/list" style="display:block;text-align:center; height: 45px;line-height: 45px;font-size: 15px;background: #45a73a;border: 0;width:100%;color: #fff;">返回</a>'
//            backNave += '</div>'
            try {
              document.getElementsByTagName('html')[0].innerHTML = article.html
//              var w = window.open()
//              w.document.open()
//              w.document.write(article.html)
//              $(w.document.body).append(inviter)
//
//              $(w.document.body).append(backNave)
//            w.close()
            } catch (e) {
              console.error('打开新窗口失败', e)
            }
          }).catch(e => {
            console.error('获取用户信息失败', e)
          })
        }).catch(e => {
          console.error('获取文章详情失败', e)
        })
      },
      getNewsDetail(id) {
        this.$request.getNewsDetail(id).then(data => {
          this.newsInfo = data
          window.location.href = data.forward_url
        }).catch(e => {
          this.$toast('获取文章详情失败：' + e.msg)
        })
      }
    }
  }
</script>

<style>

</style>